,所以我有這個jQuery的模板,我需要調用一個jQuery或本錨標記的點擊javascript函數。我曾嘗試過幾種不同的方式。jQuery的模板定位標記點擊
<a href="yourfunction()"
我用盡
$('#number').click(function(e){
所以,如果有人可以幫助這將是高度讚賞。問題中的定位標記是電話號碼,其中包含電話號碼。
@model OpenRoad.Web.Areas.Marketing.Models.MobyNumberSelectionModel
@{
ViewBag.Title = "Moby Number Selection";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@section scripts {
<script type ="text/javascript">
$('#number').click(function (e) {
alert('test');
});
});
mixpanel.track("View Marketing | Moby | Number Selection");
//$(document).on("click", "#number", function (e) {
// event.preventDefault();
// alert('test'); });
//$('#number').click(function (e) {
// Alert('test');
//});
</script>
}
<label class="lgform" style="text-align: left; padding: 10px 0;">Select state and area code:</label>
@Html.DropDownListFor(m => m.State, OpenRoad.Web.Helpers.DropDownLists.GetOptionValues("States", Model.State),
new { @class = "ddtrigger", data_url = "/Marketing/Moby/GetAreaCodes", data_template = "areaCodeTemplate", data_target = "AreaCode" })
@Html.DropDownListFor(m => m.AreaCode, (IEnumerable<SelectListItem>)ViewData["AreaCodes"],
new { @class = "ddtrigger", data_url = "/Marketing/Moby/GetPhoneNumbers",
data_template = "phoneNumberTemplate",
data_target = "phoneNumbers",
data_listtarget="true" })
@Html.HiddenFor(m => m.MobyNumber)
<script id="areaCodeTemplate" type="text/x-jquery-template">
<option value="${AreaCode}">${AreaCode}</option>
</script>
<br />
<script id="phoneNumberTemplate" type="text/x-jquery-template">
<div class="numberselectbox">
<strong>${FormattedPhoneNumber}</strong> <a href="#" id="number" class="rowSelection btn_simple" data-url="/Marketing/Moby/SelectPhoneNumber" data-redirect="/Marketing/Moby" data-value="${PhoneNumber}">Select</a><br/>
</div>
</script>
<div id="phoneNumbers">
</div>
你叫'$ (「#編號」)。單擊(..)'後,或者你的'了'標籤添加到HTML前的功能? – putvande
'$(「#號」)。點擊(函數(E){'是優選的方式,但模板已呈現並添加到DOM後它必須應用。 – bfavaretto
我增加整個視圖的問題,從而你的問題應得到回答 –