dongsui8162 2015-07-21 22:04
浏览 51
已采纳

返回时选项不自动选择

I apologize if this has already been answered. I'm still kind of learning as I go. I have searched and been unable to find a solution that works for me. I had found this one:

Firefox ignores option selected="selected"

But adding autocomplete="off" did not work for me.

Users should be able to choose an option, submit, and then when they go back have their selected option be available. This is currently working in Safari, Chrome, and Opera but not working in Firefox or IE. The select works fine, but it doesn't automatically select their choice when they go back.

I have another select on the same page which doesn't appear to have the same issue.

Here is the HTML:

<div class="col-sm-2 col-md-2">
    <div class="form-group">
    <label for="custom_1_units">Units</label>
        <select class="form-control" id="custom_1_units" name="custom_1_units" value="<?php echo"_SESSION['Custom']['custom_1_units'];" ?>" autocomplete="off">
            <option value="pages">pages</option>
            <option value="lessons">lessons</option>
            <option value="activities">activities</option>
            <option value="units">units</option>
            <option value="projects">projects</option>
        </select>
    </div>  
</div>

And here is the PHP/Javascript. It's on a .php file:

<?php echo "var cus_1_units ='" . $_SESSION['Custom']['custom_1_units'] . "';"; ?>

$("#custom_1_units").each(function() {
if($(this).text() == cus_1_units) {
    $(this).attr('selected', 'selected');            
    }                        
});
  • 写回答

2条回答 默认 最新

  • douyiji3919 2015-07-21 22:17
    关注

    The desired option is not selected because your loop is incorrect. It currently loops through an element(?), but I think you want it to loop through its children. Change the loop to the following:

    $("#custom_1_units").children("option").each(function() {
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度