onchange不适用于Firefox

时间:2015-06-24 11:09:41

标签: javascript jquery html firefox

选择onchange适用于Chrome和Opera,但它不适用于Firefox。你介意帮帮我吗?我该怎么做才能为所有浏览器修复它?



MongoDB

public class GCMIntentService extends GCMBaseIntentService {

    public static String SENDER_ID = "842798625522";
    static final String DISPLAY_MESSAGE_ACTION = "com.test.test.DISPLAY_MESSAGE";
    static final String DISPLAY_NOTICE_ACTION = "com.test.test.DISPLAY_NOTICE";
    public static boolean isNoticeActive = false;
    static final String EXTRA_MESSAGE = "message";

    static int noticeCount = 0;

    public GCMIntentService() {
        super(SENDER_ID);
    }

    @Override
    protected void onError(Context arg0, String arg1) {
        // TODO Auto-generated method stub
        System.out.println("//////// error " + arg1);
    }

    @Override
    protected void onMessage(Context context, Intent intent) {
        // TODO Auto-generated method stub

        String message = intent.getExtras().getString("message");

        if (message != null && message.trim().length() > 0) {
            try {
                JSONObject json = new JSONObject(message);
                if (json != null) {
                    String type = json.getString("type");
                    if (type.equalsIgnoreCase("chat")) {
                        // for chatting


                    } else {
                        noticeCount = SimpleUtility.getPreferenceCount(context,
                                "key");
                        noticeCount = noticeCount + 1;
                        SimpleUtility.setPreferenceNoticeCount(context, "key",
                                GCMIntentService.noticeCount);
                        displayNotice(context, message);

                        if (!(NoticeActivity.isNoticeActivityRunning)) {
                            generateNotificationNotice(context, message);
                        }
                    } // else notice
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }// if ends

    } // method ends

    @Override
    protected void onRegistered(Context context, String gcmId) {
        // TODO Auto-generated method stub
        SimpleUtility.setGCMKey(context, "key", gcmId);
        System.out.println("reg");
    }

    @Override
    protected void onUnregistered(Context context, String registrationId) {

        Toast.makeText(context, "Gcm is unregistered", Toast.LENGTH_LONG)
                .show();
        System.out.println("gcm id is " + registrationId);
    }



    @SuppressWarnings({ "deprecation" })
    private static void generateNotificationNotice(Context context,
            String message) {
        String notificationMessage = "";

        if (message != null && message.trim().length() > 0) {
            try {
                JSONObject json = new JSONObject(message);
                if (json != null) {
                    notificationMessage = json.getString("mgs");

                    // json.getString("title");
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        int icon = R.drawable.app_icon;
        long when = System.currentTimeMillis();
        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new Notification(icon, notificationMessage,
                when);

        String title = context.getString(R.string.app_name);

        Intent notificationIntent = new Intent(context, NoticeActivity.class);
         notificationIntent.putExtra("type", "notification");


        PendingIntent intent = PendingIntent.getActivity(context, 0,
                notificationIntent, 0);
        notification.setLatestEventInfo(context, title, notificationMessage,
                intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notificationManager.notify(0, notification);

    }


    static void displayMessage(Context context, String message) {
        Intent intent = new Intent(DISPLAY_MESSAGE_ACTION);
        intent.putExtra(EXTRA_MESSAGE, message);
        context.sendBroadcast(intent);
    }

    static void displayNotice(Context context, String message) {
        Intent intent = new Intent(DISPLAY_NOTICE_ACTION);
        intent.putExtra(EXTRA_MESSAGE, message);
        // context.sendBroadcast(intent);
        context.sendBroadcast(intent);
    }

} // class ends




2 个答案:

答案 0 :(得分:0)

您永远不会删除selected标记上的属性option。因此,在使用您的脚本后,您的html代码如下所示:

<select id="tehlike_sinifi"> 
    <option value="1" selected="selected">"Az Tehlikeli"</option>      
    <option value="2" selected="selected">"Tehlikeli"</option> 
    <option value="3" selected="selected">"Çok Tehlikeli"</option>     
</select> 

Firefox不知道选择哪个选项。

尝试使用函数val(),而不是设置属性selected

From jQuery documentation

  

[jQuery.val]检查或选择所有单选按钮,复选框,并选择与该组值匹配的选项。

使用函数val(),它工作正常。

if ($.inArray($("#nace_kod").val(), aztehlikeliNace) >= 0) {
    $("#tehlike_sinifi").val(1);
}
if ($.inArray($("#nace_kod").val(), tehlikeliNace) >= 0) {
    $("#tehlike_sinifi").val(2);
}
if ($.inArray($("#nace_kod").val(), coktehlikeliNace) >= 0) {
    $("#tehlike_sinifi").val(3);
}

Demo

答案 1 :(得分:0)

将您的功能脚本保留在 <iframe id="vt" width="420" autoplay="false" height="345" src="http://cache4.asset-cache.net/xd/468140002.mp4?v=1&c=IWSAsset&k=2&d=72990B68305E4FDFEE95B69A879131BCD6D7111452E48A17C03F8342D660D5A451EBC1DEC2A827C9&b=RTdG" frameborder="0" allowfullscreen></iframe> ,否则会出现错误head

<强> DEMO

ReferenceError: naceKoduDegisti is not defined