gpt4 book ai didi

javascript - 获取 Html 列表中选定的值

转载 作者:行者123 更新时间:2023-12-02 20:23:03 30 4
gpt4 key购买 nike

我想获取列表中选定的值。

<html >
<head>
<meta charset="utf-8" />
<title>Intro to jQuery Mobile</title><br />
<!--
<script type="text/javascript" src="jquery.mobile-1.0a3.min.css"></script>
<script type="text/javascript" src="jquery.mobile-1.0a3.min.js"></script>
<script type="text/javascript" src="jquery-1.5.min.js"></script>-->
<link rel="stylesheet" href="jquery.mobile-1.0a3.min.css" />
<script type="text/javascript" src="jquery-1.5.min.js"></script>
<script type="text/javascript" src="jquery.mobile-1.0a3.min.js"></script>
<script type="text/javascript">
function GetSelectedValut()
{
var list_value = document.getElementById("search1").value;
alert(list_value);
}
</script>
</head>
<body>
<!-- Page one starts-->
<div data-role="page" id="pageone">
<div data-role="header">
<h1>Header</h1>
</div>
<div data-role="content">
<ul data-role="listview" data-inset="true" >
<li id="search">
<a href="#pagetwo" value="Selected one" onclick="GetSelectedValut()">Selected one</a>
</li>
<li id="search1" onclick="GetSelectedValut()" value="Selected two">
<a href="#detailpage">Selected two</a>
</li>
<li>
<a href="#detailpage">Selected three</a>
</li>
<li>
<a href="#detailpage">Selected four</a>
</li>
<li>
<a href="#detailpage">Selected five</a>
</li>
<li>
<a href="#detailpage">Selected six</a>
</li>
/ul>
</div>
<div data-role="footer">
<h1>Footer</h1>
</div>
</div>
<!-- Page one ends-->
</body>
</html>

如果我选择选定的六种方法,一个警报框会显示选定的列表值,并且我还想与一个标签绑定(bind),即 <p>下一页的段落。提前致谢。

最佳答案

function GetSelectedValut(id)
{
var list_value = $("#"+id).attr("value");
location = "nextpage.html?val="+encodeURIComponent(list_value);
}


<a href="#pagetwo" value="Selected one" onclick="GetSelectedValut('search1')">Selected one</a>
</li>
<li id="search1" onclick="GetSelectedValut(this.id)" value="Selected two">

在下一页中(来自 this post ):

function getParameterByName(name) { 
var match = RegExp('[?&]' + name + '=([^&]*)')
.exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}

window.onload=function() {
$("#someParagraphID").html(getParameterByName("val"))
}

关于javascript - 获取 Html 列表中选定的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5271627/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com