javascript - How To Print Variable Data And String By Adding Inside Single Quotes - Stack Overflow

How To Output Variable data And String With Single Quotes.I Want To Add String After The Value Of mo.Ou

How To Output Variable data And String With Single Quotes.I Want To Add String After The Value Of mo.Output Should Be Inside Single Quotes. Output Should Be:- '123target'

<button value="123" class="btn">Button 1</button>
$('.btn').click(function(){
   var mo = $(this).val();
   var re = '''+mo+'target'';
   document.write(re);
});

How To Output Variable data And String With Single Quotes.I Want To Add String After The Value Of mo.Output Should Be Inside Single Quotes. Output Should Be:- '123target'

<button value="123" class="btn">Button 1</button>
$('.btn').click(function(){
   var mo = $(this).val();
   var re = '''+mo+'target'';
   document.write(re);
});
Share Improve this question asked Jan 13, 2017 at 7:10 nirksnirks 3402 silver badges10 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 4

Use double quote to wrap or escape it using \.

var re = '\'' + mo + 'target\'';
// or
var re = "'" + mo + "target'";

Try this,

$('.btn').click(function(){
   var mo = $(this).val();
   var re = "'"+mo + "target'";
   document.write(re);
});

Check jsfiddle link.

You haven't kept quotes properly.

$('.btn').click(function() {
  var mo = $(this).val();
  var re = "'" + mo + "target'";
  document.write(re);
});
<button value="123" class="btn">Button 1</button>

<script src="https://ajax.googleapis./ajax/libs/jquery/1.10.0/jquery.min.js"></script>

additionally you can also use ES6 template strings (backtics)

var mo = "quotes"
out.innerHTML=`some string in 'single ${mo}' and some in "double ${mo}" and also some "mix'd ${mo} content"`
<div id="out"></div>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744355767a4570223.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信