簡體   English   中英

jQuery里面的劍道內聯模板

[英]jQuery inside a kendo inline template

是否有可能在內模板中運行jQuery?

這就是我想要完成的事情。 我有一個內聯模板,其中包含用戶填寫以提交回我的控制器的表單。 我在表格上有一組單選按鈕。 如果他們點擊最后一個單選按鈕,我需要我的textarea出現並需要提交表單。

這是調用使用模板的窗口的代碼:

function onRejectClick(e) {
    e.preventDefault();

    var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
    var wnd = $("#Reject").data("kendoWindow");

    wnd.content(rejectTemplate(dataItem));
    wnd.center().open();
} 

這是我的模板:

<script type="text/x-kendo-template" id="rejectTemplate">
<div id="reject-container">
    @using (Html.BeginForm("RejectConcern", "Filter", FormMethod.Post, new { @id = "rejectConcern", @style = "width:100%", @class = "k-content" }))
    {
        @Html.AntiForgeryToken()
        <input type="hidden" id="id" name="id" value="#= data.id #" />
        <table>
            <tr>
                <td valign="top">
                    <label>Reason</label>
                </td>
                <td>
                    <label>
                        @Html.RadioButton("reasonForRejection", "NotQuestion", false, new { @id = "reasonForRejection" })Concern is not a question and will not be answered
                    </label>
                    <label>
                        @Html.RadioButton("reasonForRejection", "Inappropriate", false, new { @id = "reasonForRejection" })Concern contains inappropriate language and will not be answered
                    </label>
                    <label>
                        @Html.RadioButton("reasonForRejection", "Irrelevant", false, new { @id = "reasonForRejection" })Concern is not relevant to our business/operation and will not be answered
                    </label>
                    <label>
                        @Html.RadioButton("reasonForRejection", "Personal", false, new { @id = "reasonForRejection" })Concern is about an individual, a specific group, or area and will not be answered
                    </label>
                    <label>
                        @Html.RadioButton("reasonForRejection", "Other", false, new { @id = "reasonForRejection" })Other
                    </label>
                </td>
            </tr>
            <tr>
                <td> </td>
                <td>
                @Html.TextArea("answer",
                    new
                    {
                        @id = "answer",
                        @name = "answer",
                        @class = "k-textbox",
                        @placeholder = "Enter the reason for rejection here.",
                        @validationmessage = "The reason for rejection is required.",
                        @style = "width: 600px; min-width:600px; max-width:69%; height:200px",
                        @maxlength = "1000"
                    }
                )
                 </td>
            </tr>
            <tr>
                <td> </td>
                <td>
                    <div class="actions">
                        <button type="submit" id="rejectConcernButton" class="k-button">Submit</button>
                    </div>
                </td>
            </tr>
        </table>
    }
</div>
</script>

如何使用jQuery顯示/隱藏答案textarea字段並根據是否選中最后一個單選按鈕使其成為必需項? 如果jQuery不可能,可以通過常規JavaScript完成嗎?

如果可以在javascript中完成,那么在這種情況下可以在jQuery中完成。 我的意思是,如果你可以使用javascript代碼,你也可以使用jQuery代碼。 我建議你在widget的主元素中設置一個事件。 每個小部件都有一個名為element的屬性,它為您提供小部件的主要html元素。 因此,如果您在窗口小部件內的所有單選框中設置了一個事件,您將能夠操縱模板生成的內容,例如:

$($("#listView").data("kendoListView").element).on('change', 'input[type="radio"]', function() { });

演示

我不確定你正在使用什么小部件,但我在這個演示中使用了ListView。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM