我有一个值列表,我想将所有选定的值传递给window.open,我只能将一个变量值传递给window.open,但是我想传递多个值作为参数,下面的代码是我正在传递一个值。
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select multiple class="form-control" name="select1" id="sbone" size="20">
<option value="1"> orange </option>
<option value="2"> apple </option>
<option value="3"> bnana </option>
</select>
<script>
$(function() {
$('#mybutton').click(function() {
val = document.getElementById('sbone').value;
window.open(+val + "/report1", "mywindow1");
});
});
</script>
<input type="button" id="mybutton" name="mybutton" value="click" />
答案 0 :(得分:0)
$('#mybutton').click(function() {
var $val = $('#cars').val();
window.open(
'http://www.goole.com/'+$val,
'_blank' // <- This is what makes it open in a new window.
);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<p>
<select id="cars">
<option value="lexus">lexus</option>
<option value="bugatti">bugatti</option>
</select>
<input type="button" id='mybutton' value="button">
</p>
$('#mybutton').click(function() {
window.location = $('#sbone').val();});
答案 1 :(得分:0)
解决了我的问题的脚本:
<script>
$(function(){
$('#mybutton').click(function(){
$("#sbtwo > option").each(function() {
window.open (+this.value+"/report1", 'name_'+(new Date()).getTime(),"location=1,status=1,scrollbars=1, width=1500,height=900");
}); }); });
</script>