admin管理员组文章数量:1332377
I want to insert some html into a div suppose this:
<div id="Sag">
</div>
I am using $('#Sag').html(data)
, in order to insert data into this div...
but here is the problem my data is:
<table style="direction: rtl;float:right;">
<?php $sess = isset(Yii::app()->session['cart']) ? Yii::app()->session['cart'] : '{}';
$ses = json_decode($sess, true);
foreach ($ses as $i=>$value11){
?>
<tr style="direction: rtl;" class="cart_show">
<td>
<img class="picCart-<?php echo $i; ?>" src="<?php echo Yii::app()->request->baseUrl."/images/".$ses[$i]['properties']['pic_directory'];?>" width="100" heigh="100">
</td>
<td class="descCart-<?php echo $i; ?>">
<?php echo $ses[$i]['properties']['description'];?>
</td>
<td class="priceCart-<?php echo $i; ?>">
<?php echo $ses[$i]['properties']['price'];?>
</td>
<td class="quantityCart-<?php echo $i; ?>">
<input type="text" style="width: 20px;" class="voroodi" value="<?php
echo $ses[$i]['quantity'];
?>">
<button name="delete_from_cart-<?php echo $i; ?>" class="btnDel">??? </button>
<button name="modify_cart-<?php echo $i; ?>" class="btnModify">?????</button>
</td>
</tr>
<?php } ?>
</table>
so how can I escape "
,'
, ...? should I use a \
before each one, or is there something like @
in C# to use in javascript?
I want to insert some html into a div suppose this:
<div id="Sag">
</div>
I am using $('#Sag').html(data)
, in order to insert data into this div...
but here is the problem my data is:
<table style="direction: rtl;float:right;">
<?php $sess = isset(Yii::app()->session['cart']) ? Yii::app()->session['cart'] : '{}';
$ses = json_decode($sess, true);
foreach ($ses as $i=>$value11){
?>
<tr style="direction: rtl;" class="cart_show">
<td>
<img class="picCart-<?php echo $i; ?>" src="<?php echo Yii::app()->request->baseUrl."/images/".$ses[$i]['properties']['pic_directory'];?>" width="100" heigh="100">
</td>
<td class="descCart-<?php echo $i; ?>">
<?php echo $ses[$i]['properties']['description'];?>
</td>
<td class="priceCart-<?php echo $i; ?>">
<?php echo $ses[$i]['properties']['price'];?>
</td>
<td class="quantityCart-<?php echo $i; ?>">
<input type="text" style="width: 20px;" class="voroodi" value="<?php
echo $ses[$i]['quantity'];
?>">
<button name="delete_from_cart-<?php echo $i; ?>" class="btnDel">??? </button>
<button name="modify_cart-<?php echo $i; ?>" class="btnModify">?????</button>
</td>
</tr>
<?php } ?>
</table>
so how can I escape "
,'
, ...? should I use a \
before each one, or is there something like @
in C# to use in javascript?
- 1 Your data is what? How are you getting that chunk of code? – epascarello Commented Feb 19, 2012 at 14:39
- What do you intend to happen when you it in the div. Note that the php will not execute as javascript is clientside. – Ash Burlaczenko Commented Feb 19, 2012 at 14:40
- the data is something that is using the session in order to show the user's cart, so is there any other idea for this purpose. P.S: the content of the specified div would be shown to the user as a pop up window so I think it's my solution to show the user this content without reloading the page – Ehsan Commented Feb 19, 2012 at 14:49
1 Answer
Reset to default 8so how can I escape ",',... should I use a \ before each one, or is there something like @ in c# to use in javascript
No, JavaScript doesn't have an equivalent of C#'s @
feature.
In JavaScript, strings can be quoted by either single ('
) or double ("
) quotes. Within a quote, only the style you've used for quoting needs to be escaped. So within a string quoted with single quotes, double quotes don't need escaping; and within a string using double quotes, single quotes don't need escaping. (It's always okay to escape them, all that varies is whether you have to.)
So you usually pick the one you're using least, and use that for the main string's delimiter. E.g.:
str = "This uses doubles, so I don't have to worry about the ' in \"don't\".";
Note that I didn't have to escape '
there, but I did have to escape "
.
Similarly:
str = 'This uses singles, so I don\'t have to worry about "quoting" things.';
There I had to escape '
but not "
.
本文标签: Javascript how to escape charactersStack Overflow
版权声明:本文标题:Javascript how to escape characters - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742298177a2449146.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论