What disadvantages are there to the <button> tag?

后端 未结 11 1125
灰色年华
灰色年华 2020-11-29 01:13

I started using a diagnostic css stylesheet, e.g. http://snipplr.com/view/6770/css-diagnostics--highlight-deprecated-html-with-css--more/

One of the suggested rules

11条回答
  •  死守一世寂寞
    2020-11-29 01:49

    as far as I am concerned the difference between submit and button tags is this: gives you the option to have different text displayed than the element's value

    Let's say you have a list of products then next to each product you want a button to add it to the customer's cart:

    product1 : 
    product2 : 
    product3 : 
    

    then you could do this:

    
    

    Now the problem is that IE will send the form with value="add to cart" instead of value="product2"

    The easiest way to workaroound this issue is by adding onclick="this.value='product2'"

    So this:

    
    

    will do the trick on all major browsers - I have actually used this on a form with multiple buttons and works with Chrome Firefox and IE

提交回复
热议问题