此代码的前端已经开发,并在多个地方使用jquery来拦截用户的点击。在这里,我有一个单选按钮,当点击时,会触发下面的事件。我需要对页面加载事件后面的代码中的html输入元素进行此操作,以预先填充单选按钮。我怎么能这样做?
要开火的Jquery事件:
//checkboxes
$('.questions-form a.toggle').bind('click', function (event) {
//jquery magic
}
我需要选择的html元素,或点击:
<div id="form-error" style="display: none"></div>
<div class="questions-form" id="shipping-questions-form">
<div class="question question-textarea has-subquestions">
<div class="question-intro clearfix">
<h2>Did You Receive The Product As Ordered?</h2>
<div class="no-yes answer-acceptable">
<div class="no"><label class="label-1" for="shipping_question_ID_product_received_as_ordered_not_acceptable">Not Acceptable</label></div>
<a href="#" class="toggle"></a>
<div class="yes"><label class="label-2" for="shipping_question_ID_product_received_as_ordered_acceptable">Acceptable</label></div>
<label class="universal-label"></label>
<input type="radio" id="shipping_question_ID_product_received_as_ordered_not_acceptable" name="shipping-question-ID-product-received-as-ordered" value="Not Acceptable" runat="server">
<input type="radio" id="shipping_question_ID_product_received_as_ordered_acceptable" name="shipping-question-ID-product-received-as-ordered" value="Acceptable" checked="true" runat="server">
</div>
</div>
答案 0 :(得分:1)
您可以使用
ScriptManager.RegisterStartupScript Method (Page, Type, String, String, Boolean);
参数
**page**
Type: System.Web.UI.Page
The page object that is registering the client script block.
**type**
Type: System.Type
The type of the client script block. This parameter is usually specified by using the typeof operator (C#) or the GetType operator (Visual Basic) to retrieve the type of the control that is registering the script.
**key**
Type: System.String
A unique identifier for the script block.
**script**
Type: System.String
The script to register.
**addScriptTags**
Type: System.Boolean
true to enclose the script block with <script> and </script> tags; otherwise, false.
答案 1 :(得分:0)
以下代码执行了所需的功能。我通过“单击”附加到对象的锚点来调用此函数。
<div class="no"><label class="label-1" for="shipping_question_ID_product_received_as_ordered_not_acceptable">Not Acceptable</label></div>
<a href="#" class="toggle" runat="server" id="shipping_question_ID_product_received_as_ordered_link"></a>
然后在后面的代码中:
var autoRunScript = string.Format("<script>$(function() {{ $('#{0}').click(); }} );</script>", shipping_question_ID_product_received_as_ordered_link.ClientID);
Page.RegisterClientScriptBlock("keyClientBlock", autoRunScript);