我正在使用jQuery创建自定义单选按钮,我有一个问题.当点击与收音机相关联的标签时,点击事件会触发两次,如果我只点击收音机本身它工作正常(实际上它不是我点击的收音机,而是包裹整个输入和标签的div).这是代码:
HTML:
<div id="box">
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem>RADIO1</asp:ListItem>
<asp:ListItem>RADIO2</asp:ListItem>
<asp:ListItem>RADIO3</asp:ListItem>
</asp:RadioButtonList>
</div>
Run Code Online (Sandbox Code Playgroud)
jQuery的:
<script type="text/javascript">
$(function () {
$('#box').find('input:radio').each(function (i) {
var input = $(this);
// get the associated label using the input's id
var label = $('label[for=' + input.attr('id') + ']');
// wrap the input + label in a div
$('<div class="custom-radio"></div>').insertBefore(input).append(label, input);
var wrapperDiv = input.parent();
// find all inputs in this set using the shared name attribute
var allInputs = $('input[name=' + input.attr('name') + ']');
// necessary …Run Code Online (Sandbox Code Playgroud) 我需要javascript正则表达式,允许英语或希伯来语字符,但不是两者混合.例如:
我需要一个c#中的正则表达式,它将在字符串文字中转义双引号.所以,如果我有这个字符串:"这个"怎么样,"那个"怎么样.我将能够在javascript中使用它而不会出错.因为我正在将这个文字作为js var写入页面.
编辑:我将尝试解释有关该问题的更多信息.我在这样的页面写messege:
string UserMsg = GetMessageText(999);
StringBuilder script = new StringBuilder();
script.AppendFormat("var UserMsg =\"{0}\";{1}", UserMsg, Environment.NewLine);
ScriptManager.RegisterClientScriptBlock(this, GetType(), "scriptparams", script.ToString(),true);
Run Code Online (Sandbox Code Playgroud)
现在让我们说messege 999是这样的:"我们在你的细节中发现了一个"问题".这导致js错误.