gpt4 book ai didi

Javascript onchange 函数在移动设备上的选择菜单中不起作用

转载 作者:行者123 更新时间:2023-11-30 06:11:59 24 4
gpt4 key购买 nike

            <script type="text/javascript"> 
var urlmenu = document.getElementById( "rpdropdown3" );
urlmenu.remove(1);
urlmenu.onchange = function() {
window.open( this.options[ this.selectedIndex ].value, "_blank" );
var options = rpdropdown3.options;
// Look for a default selected option
for (var i=0, iLen=options.length; i<iLen; i++) {

if (options[i].defaultSelected) {
rpdropdown3.selectedIndex = i;
return;
}
}

// If no option is the default, select first or none as appropriate
selectElement.selectedIndex = 0; // or -1 for no option selected
};

</script>';

$postslist = get_posts( $args );
foreach( $postslist as $posts ){
$string .= '<option value="' . get_the_permalink($posts) . '">-- ' .get_the_title($posts).'</option> ';
}

不适用于任何移动浏览器(适用于计算机浏览器),选择下拉菜单无法按预期打开链接

最佳答案

看起来它确实有效,但它作为弹出窗口被阻止了。如果 window.open 不是由用户操作触发的,例如按钮或链接,则不能使用它。

foreach ($postslist as $posts) { ?>
<select id="rpdropdown" onchange="if (this.value) window.location.href=this.value">
<option value="" selected disabled>OPTION 1</option>
<option value="<?php echo get_the_permalink($posts) ?>" onchange="window.open (this.value)"> -- <?php echo get_the_title($posts) ?></option>
</select>

<?php }

在我的例子中,我使用了 onchange="if (this.value) window.location.href=this.value" 并且我试图让它在新选项卡中打开。

他们在这里和其他许多帖子中讨论了这个问题:javascript window.open in safari

关于Javascript onchange 函数在移动设备上的选择菜单中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58378430/

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