在URL中传递下拉列表的选定值
Passing selected value of dropdownlist in URL
我有一个下拉列表,当我从列表中选择一个项目时,它会打开一个新窗口。如何将dropdownlist值传递到URL中的新窗口?
我的代码如下:
<asp:DropDownList ID="ddlAdd" runat="server" CssClass="ddl" OnChange="javascript:openWindow('add.aspx?ddlAddValue=', 800, 885)">
<asp:ListItem>One</asp:ListItem>
<asp:ListItem>Two</asp:ListItem>
<asp:ListItem>Three</asp:ListItem>
</asp:DropDownList>
这是JavaScript函数:
function openWindow(url, windowHeight, windowWidth)
{
var centerHeight = (screen.height - windowHeight) / 2;
var centerWidth = (screen.width - windowWidth) / 2;
var features = "height=" + windowHeight + ", width=" + windowWidth + ", top=" + centerHeight + ", left=" + centerWidth + ", scrollbars=" + 1;
var popUp = window.open(url, "", features);
}
您可以简单地引用this.value
来获取底层select的值。
OnChange="javascript:openWindow('add.aspx?ddlAddValue=' + escape(this.value), 800, 885)"
此外,如果你是这样滚动的话,这在jQuery中很容易处理:
$(function(){
$('select[id$=ddlAdd]').change(function () {
var addValue = $(this).val();
if (addValue) {
// window opening logic here
}
return false;
});
});
您可以像这样将下拉对象直接传递到javascript中。。。
onchange="openWindow('add.aspx?ddlAddValue=', 800, 885, this)"
(注意,onchange
命令中不需要javascript:
前缀——浏览器已经知道它是javascript)
然后在你的职能。。。
function openWindow(url, windowHeight, windowWidth, dd)
{
url = url + encodeURIComponent(dd.options[dd.selectedIndex].value);
...
相关文章:
- 根据url填充表单选择下拉列表
- 将下拉列表“选择值”传递到 URL
- 使 URL 开始选择下拉列表
- 如何根据选择下拉列表从表单重定向到 URL
- 映射下拉列表选择到URL
- 选择下拉列表需要在选中时显示提供商的详细信息-无法通过我的脚本显示url
- 在URL中传递下拉列表的选定值
- 更改URL并保留“更改”事件下拉列表中的值
- 使用URL参数选择的下拉列表
- 使用javascript进行动态php下拉列表(url)
- 如何通过单击链接为具有 URL 值的下拉列表设置值
- 在 Javascript URL 中传递两个变量,以根据传递的值更新下拉列表
- 从下拉列表中打开 URL
- HTML下拉列表将我带到错误的URL
- JQuery 根据 HTML 下拉列表选择查找并替换 URL 中的查询字符串
- 从 URL 获取选项值,以显示下拉列表中的特定菜单项
- 如何使用AngularJS中的下拉列表来更新URL以从中抓取图片
- 在jquery中用两个下拉列表更新URL
- 如何使Bootstrap Select2下拉列表在单击时转到选定的URL
- 通过wordpress中的URL从下拉列表中选择选项