jquery get a custom (made up) Attribute value

前端 未结 3 1113
终归单人心
终归单人心 2021-01-13 12:08

I have a the following html piece :

&l
相关标签:
3条回答
  • 2021-01-13 12:34

    all you have to do is :

    fValue = $(input).attr("store-id");
    

    your snippet is trying to add to the 'value' attribute of a div (which does not exist)

    0 讨论(0)
  • 2021-01-13 12:43

    This works perfectly:

    getComments = function(input) {
      fValue =  $(input).attr("store-id");
      alert('the ID :'+fValue);
    }
    

    http://jsfiddle.net/mHBuE/

    0 讨论(0)
  • 2021-01-13 12:52

    Take a look at jQuery custom selectors. Personally, I would use HTML5 data attributes for cases such as this which is already supported in jQuery.

    For whatever it's worth, considering the parameter I believe what are you trying to originally perform should be done like

    getComments = function(input) {
       fValue =     $(input).html( $(input).attr("store-id") );
       alert('the ID :'+fValue.html());
    
       }
    
    0 讨论(0)
提交回复
热议问题