在 Select 标签上选择一个选项并在重新加载/刷新时将其保留在那里

Select我正在尝试在您选择并单击其中的位置后创建一个标签option,它将加载到标签href所option具有的值。加载后,option您选择的将在标签上突出显示select。


到目前为止,从我搜索过的内容来看,我只有:


HTML:


    <select id="jumpid" onchange="jump(this)" >

        <option value="index.php?ID=1">Val 1</option>

        <option value="index.php?ID=2">Val 2</option>

        <option value="index.php?ID=3">Val 3</option>

        <option value="index.php?ID=4">Val 4</option>

        <option value="index.php?ID=5">Val 5</option>

        <option value="index.php?ID=6">Val 6</option>

        <option value="index.php?ID=7">Val 7</option>

    </select>

记者:


<script>

    function jump(selectedLink){

    var chpSelect = selectedLink.value;

    location.href=document.getElementById("jumpid").value;

}

</script>

例如,当我选择某些内容时Val 3,浏览器将重新加载到index.php?ID=3它的内容。但select标签仍然显示Val 1,我希望它留在Val 3。


侃侃尔雅
浏览 215回答 1
1回答

守着一只汪

它很粗糙,但它会起作用:<?php$id=0;if(isset($_GET['ID']){&nbsp; &nbsp; $id = $_GET['ID'];}?>&nbsp; &nbsp;&nbsp;<select id="jumpid" onchange="jump(this)" >&nbsp; &nbsp; &nbsp; &nbsp; <option value="index.php?ID=1" <?php if($id==1){echo "selected";}?>>Val 1</option>&nbsp; &nbsp; &nbsp; &nbsp; <option value="index.php?ID=2" <?php if($id==2){echo "selected";}?>>Val 2</option>&nbsp; &nbsp; &nbsp; &nbsp; <option value="index.php?ID=3" <?php if($id==3){echo "selected";}?>>Val 3</option>&nbsp; &nbsp; &nbsp; &nbsp; <option value="index.php?ID=4" <?php if($id==4){echo "selected";}?>>Val 4</option>&nbsp; &nbsp; &nbsp; &nbsp; <option value="index.php?ID=5" <?php if($id==5){echo "selected";}?>>Val 5</option>&nbsp; &nbsp; &nbsp; &nbsp; <option value="index.php?ID=6" <?php if($id==6){echo "selected";}?>>Val 6</option>&nbsp; &nbsp; &nbsp; &nbsp; <option value="index.php?ID=7" <?php if($id==7){echo "selected";}?>>Val 7</option>&nbsp; &nbsp; </select>
打开App,查看更多内容
随时随地看视频慕课网APP