attr

Changing onclick attribute using replace with jQuery

隐身守侯 提交于 2019-11-28 01:41:10
问题 Do someone know what is the best way to replace some string inside a onclick attribute ? I need to get the current value and replace some text inside parameters. Exemple, I have this link: <a href="#" onclick="myfunction('parameter1a','parameter1b')">My link</a> And I want this: <a href="#" onclick="myfunction('parameter2a','parameter2b')">My link</a> In other words, I want something like this: $('a').attr('onclick', $(this).attr('onclick').replace('1', '2')); And I know I can do this, but I

Use declare styleable to set custom component input type

旧巷老猫 提交于 2019-11-27 20:51:04
问题 I have a CompositeComponent (EditText+ImageButton) When clicking on button the edittext content will be cleared. It is working fine. My problem is setting attributes to my component. I am using declare-styleable to set attributes to my component. I am successful at setting minLines, maxLines and textColor. How can I set inputtype to my component via xml. my attributes.xml <?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="CET"> <attr name="MaxLines" format="integer"/>

Setting new value for an attribute using jQuery

放肆的年华 提交于 2019-11-27 19:58:26
I am trying to set a new vale of a custom attribute of a div using attr() . I found out it can be done using .attr( attributeName, value ) , but when I try it it's not working. Here is the part of my code I am interested in: $('#amount').attr( 'datamin','1000') and the div that has the custom attribute is <div id="amount" datamin=""></div> Here is the whole example: $(function() { $( "#slider-range" ).slider({ range: true, min: <?php echo $min_val;?>, max: <?php echo $max_val;?>, values: [ <?php echo $min_val;?>, <?php echo $max_val;?> ], slide: function( event, ui ) { $( "#amount" ).html( "<

How do I add selectableItemBackground to an ImageButton programmatically?

帅比萌擦擦* 提交于 2019-11-27 19:58:10
android.R.attr.selectableItemBackground exists, but how do I add it programatically to an ImageButton? Also, how would I go about finding the answer in the documentation? It's mentioned here , but I don't see any explanation of how it's actually used. Actually, I rarely seem to find the documentation useful, but I'm hoping that's my fault and not that of the documentation. Timuçin Here is an example using answer here: How to get the attr reference in code? // Create an array of the attributes we want to resolve // using values from a theme // android.R.attr.selectableItemBackground requires

Does the attr() in jQuery force lowercase?

守給你的承諾、 提交于 2019-11-27 15:26:38
I'm trying to manipulate the svg 'viewBox' attribute which looks something like this: <svg viewBox="0 0 100 200" width="100" ...> ... </svg> Using $("svg").attr("viewBox","..."); However, this creates a new attribute in the element called "viewbox". Notice the lowercase instead of intended camelCase. Is there another function I should be using? I was able to use pure javascript to get the element and set the attribute by using var svg = document.getElementsByTagName("svg")[0]; and svg.setAttribute("viewBox","..."); Nick Hedberg Per http://www.w3.org/TR/xhtml1/#h-4.2 "XHTML documents must use

How to replace element's attr href with each ? // strip url

帅比萌擦擦* 提交于 2019-11-27 15:12:13
im trying to change href with each method, here is demo, inspect a, you'll see there is no change html: <a href="#/news">News</a> <a href="#/news/detail">Detail</a> <a href="#/sport">Sport</a> <a href="#/sport/football">Football</a>​​​​​​​​​​​​ jQuery: $('a').each(function() { $(this).attr('href').replace('#/',''); //tried to erase #/ from all hrefs });​ The code you posted will get the value as a string then properly replace the values but it immediately discards the result. You need to pass in the replaced value to attr . Try the following $('a').each(function() { var value = $(this).attr(

jQuery attr('onclick')

风流意气都作罢 提交于 2019-11-27 14:25:14
问题 I'am trying to change "onclick" attribute in jQuery but it doesn't change, here is my code: $('#stop').click(function() { $('next').attr('onclick','stopMoving()'); } I have an element with id="stop" and when user clicks on it I want to change an onclick attribute on element which has id="next". If someone knows where is the solution please help! 回答1: Do it the jQuery way (and fix the errors): $('#stop').click(function() { $('#next').click(stopMoving); // ^-- missing # }); // <-- missing ); If

Why jQuery 1.9+ attr() method not deprecated?

早过忘川 提交于 2019-11-27 13:07:56
Can I, a jQuery1.9+ software developer, "deprecate" the use of the attr() method in my day-by-day work? As showed in many questions, .prop() vs .attr() (main) jQuery attr vs. prop, there are a list of props? jQuery attr vs prop? Migrating jQuery 1.8.3 to 1.9.0 - Replacing deprecated .attr() ... etc. ... there are a lot of confusion about "use attr or use prop?" , and, by my (developer's) view point, for all uses of attr() method, we can use prop instead: backward-compatibility : coding new software not need this; performance : John says "Accessing properties through the .attr() method will be

JQuery - File attributes

て烟熏妆下的殇ゞ 提交于 2019-11-27 11:15:39
问题 Trying to access file attributes from an input field after a file is selected. Tried this but get the error 'file not defined' var file = $("#uploadedfile").prop("files")[0]; var fileName = file.fileName; var fileSize = file.fileSize; alert("Uploading: "+fileName+" @ "+fileSize+"bytes"); 回答1: If #uploadedfile is an input with type "file" : var file = $("#uploadedfile")[0].files[0]; var fileName = file.name; var fileSize = file.size; alert("Uploading: "+fileName+" @ "+fileSize+"bytes");

jQuery check if attr = value

左心房为你撑大大i 提交于 2019-11-27 11:06:35
问题 I seem to be having trouble with my code. I need to say: if ( $('html').attr('lang').val() == 'fr-FR' ) { // do this } else { // do that } When I check the console, I just get an error telling me this isn't a function. Help would be appreciated. Thanks, 回答1: Just remove the .val(). Like: if ( $('html').attr('lang') == 'fr-FR' ) { // do this } else { // do that } 回答2: jQuery's attr method returns the value of the attribute: The .attr() method gets the attribute value for only the first element