Javascript 如何在引导模式下根据用户从选项菜单中的选择导航到URL?
我正在尝试实现一个功能,但似乎找不到正确的解决方案 在引导模式中,我有一个下拉菜单,如下所示: 目标: 用户启动创建模式 用户从下拉列表中选择项目 单击“创建”按钮时,用户将导航到所选项目的URL。 谢谢你的帮助Javascript 如何在引导模式下根据用户从选项菜单中的选择导航到URL?,javascript,jquery,html,css,twitter-bootstrap,Javascript,Jquery,Html,Css,Twitter Bootstrap,我正在尝试实现一个功能,但似乎找不到正确的解决方案 在引导模式中,我有一个下拉菜单,如下所示: 目标: 用户启动创建模式 用户从下拉列表中选择项目 单击“创建”按钮时,用户将导航到所选项目的URL。 谢谢你的帮助 TK实现这一点的方法有很多。因为使用jQuery的引导 $(function() { $('button[data-dismiss]').click(function() { window.location.href = $('#select').val(
TK实现这一点的方法有很多。因为使用jQuery的引导
$(function() {
$('button[data-dismiss]').click(function()
{
window.location.href = $('#select').val()
});
}未经测试
(function() {
var dialog = $('#your-dialog-selector'), // Your dialog
select = $('#createNewSelect'); // The select box (get rid of the second id attribute [id="select"]!)
// Listen for the form's submit event
select.closest('form').on('submit', function(e) {
e.preventDefault(); // Don't actually submit
window.location = "/" + select.val(); // Navigate
});
// To open the dialog.. put it wherever
dialog.modal('show');
})();
您可以使用“创建”按钮获取选择列表的B值-在您的示例中也不是这样-您有两个id用于该选择-每个元素只能有一个id。然后您可以构建链接并使用window.location导航到它。请注意,我只是将一个谷歌查询作为链接-您需要根据需要进行修改 $document.readyfunction{ $'createLink'。单击函数{ var sel=$'createNewSelect'.val; var link=http:www.google.com/?q=+sel; console.loglink; //使用window.location=link;允许导航到链接位置 } } &时代; 选择要添加的项目 租赁 出售 地方 创造
只需在选项值中写入URL目标 $create\u btn.clickfunction{ var url=$'select'.val; //alerturl; window.location=url; }; &时代; 选择要添加的项目 租赁 出售 地方 创造
对于初学者,要使onsubmit属性按照您概述的方式工作,submit按钮需要是表单标记的子级。目前它在模式页脚中处于它之外。除此之外,我相信您希望通过所选的选项。这和makePaththis中的不同。您正在寻找类似document.getElementById'select'[document.getElementById'select.selectedIndex].value的内容。我感谢您的帮助。此解决方案似乎没有将所选项目传递回浏览器…我只是检查了一下。对我来说很有魅力。你试过真正的档案吗?新页面不会显示在代码栏中。
(function() {
var dialog = $('#your-dialog-selector'), // Your dialog
select = $('#createNewSelect'); // The select box (get rid of the second id attribute [id="select"]!)
// Listen for the form's submit event
select.closest('form').on('submit', function(e) {
e.preventDefault(); // Don't actually submit
window.location = "/" + select.val(); // Navigate
});
// To open the dialog.. put it wherever
dialog.modal('show');
})();