English 中文(简体)
Html. 检查 箱子立克事件正在越狱。
原标题:Html.CheckBox onclick event is getting escaped

我试图制作一系列的检查箱,以更新跟踪检查箱数量(如12个检查箱中的4个)。 I ve创设了“ Java”字典功能updateS selected,该功能处理的是,它要求识别检查箱的长短和类别,以便计算,因此,我尝试用这一代码生成每个检查箱:

@Html.CheckBox(string.Format("contentprofilestate[{0}].selected", i), 
  new { onclick = "updateSelected( " + selectedSpanId + " ,  " + checkboxClass + " )" })

产生以下超文本:

<input id="contentprofilestate_6__selected" name="contentprofilestate[6].selected" 
 onclick="updateSelected(&#39;StMarySpan&#39;, &#39;StMaryCheck&#39;)"
 type="checkbox" value="true" />

How can I get the onclick event handler to render without escaping the apostrophes? Alternatively, is there a better way to accomplish this task (if so, feel free to use jQuery in your suggestion)?

www.un.org/Depts/DGACM/index_spanish.htm 注:

I created a new project and created this view and it still escaped the apostrophes:

@{
    ViewBag.Title = "index";
}

<h2>index</h2>

@Html.CheckBox(string.Format("contentprofilestate[{0}].selected", 0), new { onclick = "updateSelected( " + "test" + " ,  " + "test2" + " )" })

<> 替代解决方案>

I was not able to figure out how to keep the apostrophes from being escaped, so I wrote some jQuery logic to do what I need without any inline JavaScript:

jQuery(document).ready(function () {
    jQuery( :checkbox ).click(function () {
        var clientHeader = jQuery(this).closest( .client-header );
        var clientCheckedSpan = clientHeader.find( .client-checked );
        var inputChecked = clientHeader.find( input:checked );
        clientCheckedSpan.text(inputChecked.length);
    });
});
最佳回答

很奇怪的是,apos正在编码。 我认为,他们会是在进行快速测试之后进行的。 在这方面,可能还有其他事情要做。 如果你把这1条线放在空洞的视野中,那么,我把你打得的 t子就会产生同样的问题。

至于任何其他替代办法,你可以很容易地获得使用j Query的选定检查箱的数量:

var numChecked = $("input:checked[id^=contentprofilestate]").size();
问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签