我使用nuget安装基础和jquery ui(安装了jquery)。我有一个正在工作的MVC 5网站。
在添加基础之前,jQuery自动完成控制工作正常。但是,安装控件后仍然可以使用,但是您在其中进行选择的下拉菜单消失了。
我遇到了这个解决方案,它与Zurb Foundation一起使用了样式自动完成功能,这是我认为的同一个人... http://ezra.keddell.co.nz/implementing-jquery-autocomplete-in-zurb-foundation-4/。它们是我在搜索中遇到的唯一解决方案。但是我认为这对我不起作用,因为从我可以知道当您通过nuget安装基础时,它并不是jquery附带的。因此,他要使用以下代码修改的文件无效,我也不知道哪些文件是正确的文件。我也不明白为什么这很有意义。
<script>
document.write('<script src=' +
('__proto__' in {} ? 'js/vendor/zepto' : 'js/vendor/jquery') +
'.js><\/script>')
</script>
我想我正在寻找一种方法来使jquery ui和foundation一起工作,以实现自动完成控件。是否可以告知Foundation停止工作一段时间或使其不影响自动完成控件的样式。
我拥有的确切代码是...
Layout.cshtml
<head>
<meta charset="utf-8" />
@Styles.Render("~/Content/foundation/css")
@Styles.Render("~/Content/site.css")
@RenderSection("head", required: false)
@Scripts.Render("~/bundles/modernizr")
</head>
<div id="mainWrap" class="row">
<div class="Columns small-12 small-centered">
@RenderBody()
</div>
</div>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/foundation")
<script>
$(document).foundation();
</script>
@*Use the Scripts section to define page specific scripts*@
@RenderSection("scripts", required: false)
index.cshtml
<script>
$(document).ready(function () {
$("#Name").autocomplete({
// how does the request get a value?
source: function GetRemoteData(request, response) {
var name = $("#Name").val();
$.ajax({
type: "GET",
url: "/api/attendees/" + name,
cache: false,
data: request,
dataType: "json",
success: function (json) {
// call autocomplete callback method with
response($.map(json, function (name, val) {
return {
label: name,
value: val
};
}));
},
error: function (XMLHttpRequest, textStatus, e) {
alert("error - " + textStatus);
console.log("error", textStatus, errorThrown);
}
}); // end $.ajax
},
minLength: 2,
select: function (event, ui) {
alert("you have selected " + ui.item.label + "Id: " + ui.item.value);
$("#Name").val(ui.item.label);
return false;
}
}); // end autocomplete
// supposedly to help foundation and jquery ui work together.
$('.ui-autocomplete').addClass('f-dropdown');
}); // end ready
</script>
@using (Html.BeginForm("Submit", "Home")) {
@*<label>Your Name:</label> <input type="text" id="Name" name="Name" value="@Html.Raw(Model.Firstname) @Html.Raw(Model.LastName)" /> <br />*@
<label>Your Name:</label> <input type="text" id="Name" name="Name" value="" /> <br />
@Html.LabelFor( x=> x.Attending ) @Html.CheckBoxFor( x=> x.Attending ) @*<label>Attending:</label>*@ @*<input type="checkbox" id="Attending" name="Attending" />*@ <br />
@Html.LabelFor( x => x.Windermere ) @Html.CheckBoxFor( x => x.Windermere ) @*<label>Staying at the Windermere Manor:</label>*@ @*<input type="radio" id="radioYes" /> <input type="radio" id="radioNo" /> <input type="radio" id="radioMaybe" />*@ <br />
@Html.TextAreaFor( x => x.Notes )<label>Notes:</label> @*<textarea id="AttendanceNotes" name="AttendanceNotes"> </textarea>*@ <br />
<button id="Submit" name="Sumbit">Submit</button>
}
确实很不幸,但这并不是Foundation和jquery ui之间的冲突……如果您仔细查看上方的内容,您会注意到我没有包括jquery UI css样式表。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句