[英]Javascript how to escape characters
我想在div中插入一些html:
<div id="Sag">
</div>
我正在使用$('#Sag').html(data)
,以便將數據插入到此div中……但這是我的數據存在的問題:
<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>
所以我該如何轉義"
, '
,...? "
,我應該在每個\\
之前使用\\
,還是在JavaScript中在C#中使用類似@
東西?
所以我該如何轉義“,',...我應該在每個字符之前使用\\,還是在JavaScript中在c#中使用@
不,JavaScript沒有C#的@
功能。
在JavaScript中,字符串可以用單引號( '
)或雙引號( "
)引起來。在引號內,只需要轉義用於引用的樣式。因此,在用單引號引起來的字符串中,雙引號不要不需要轉義;在使用雙引號的字符串中,單引號不需要轉義(逃脫它們總是可以的 ,所有不同之處在於是否必須這樣做)。
因此,通常選擇最不常用的那個,並將其用作主字符串的定界符。 例如:
str = "This uses doubles, so I don't have to worry about the ' in \"don't\".";
請注意,我沒有逃跑'
,但我確實有逃避"
。
類似地:
str = 'This uses singles, so I don\'t have to worry about "quoting" things.';
在那兒我必須逃脫'
而不是"
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.