简体   繁体   English

Safari的Javascript不起作用-所有其他浏览器都起作用

[英]Javascript with Safari doesn't work - all other browser do

I have this script which duplicates the form fields when a "Same as Billing" checkbox is clicked from one form to another. 我有一个脚本,当从一个表单单击“与计费相同”复选框时,它会复制表单字段。 It works fine except in Safari it won't transfer the state selection from the original form. 它工作正常,但在Safari中不会从原始表单转移状态选择。 The form field for the state is a select box. 状态的表单字段是一个选择框。 Any help is appreciated. 任何帮助表示赞赏。

$(document).ready(function () {
    $("#same").click(function(){
        if($("#same:checked").length >= 0) {
            $('#first_name_ship').val($('#first_name_bill').val());
            $('#last_name_ship').val($('#last_name_bill').val());
            $('#address1_ship').val($('#address1_bill').val());
            $('#address2_ship').val($('#address2_bill').val());
            $('#city_ship').val($('#city_bill').val());
            var selected_state = $('#state_bill_select   option:selected').val();
            $('#state_ship_select option[value=' + selected_state + ']').attr('selected','selected');
            $('#zip_ship').val($('#zip_bill').val());

You can use 您可以使用

.prop('selected', true)

instead of 代替

.attr('selected','selected');

which might work better with safari in general. 一般而言,与野生动物园搭配使用可能会更好。

Try that out. 试试看。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM