开发者

On form submit get LocalStorage Item and submit it

开发者 https://www.devze.com 2023-04-02 11:50 出处:网络
I\'m trying to get a localStorage item and set a form\'s attribute but it doesn\'t seem to work which localStorage is used.

I'm trying to get a localStorage item and set a form's attribute but it doesn't seem to work which localStorage is used.

The localStorage item 'formitem' has value "somevalue".

This is what I currently have which doesn't work:

$(".form").submit(function() {
        if (localStorage.getItem("formitem") == "som开发者_开发问答evalue"){ 
            $(".form").attr('action', 'http://www.google.com')
        }else {$(".form").attr('action', 'http://www.bing.com')}
});

What I'm I doing wrong?


Try this

$(".form").submit(function() {
        if (parseInt(localStorage["formitem"]) == 1){ 
            $(".form").attr('action', 'http://www.google.com')
        }else {$(".form").attr('action', 'http://www.bing.com')}
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号