setattribute

JavaScript load Images in an Array and Show in Image Source

我与影子孤独终老i 提交于 2019-12-08 18:15:35
I created an array of images function initialize(){ //add our 10 images to our array imgArray[imageNum++] = new imageItem(imageDir + "img1.jpg"); imgArray[imageNum++] = new imageItem(imageDir + "img2.jpg"); imgArray[imageNum++] = new imageItem(imageDir + "img3.jpg"); } var totalImgs = imgArray.length; I then create a function that is linked with a in my html file: <button id="startButton" onclick="startImage()">Start</button> function startImage(){ document.getElementById("pic").setAttribute("src", imgArray[0].src); } My image tag : <img id="pic" src="" height="300" width="500" border="0" alt=

JavaScript load Images in an Array and Show in Image Source

二次信任 提交于 2019-12-08 08:37:05
问题 I created an array of images function initialize(){ //add our 10 images to our array imgArray[imageNum++] = new imageItem(imageDir + "img1.jpg"); imgArray[imageNum++] = new imageItem(imageDir + "img2.jpg"); imgArray[imageNum++] = new imageItem(imageDir + "img3.jpg"); } var totalImgs = imgArray.length; I then create a function that is linked with a in my html file: <button id="startButton" onclick="startImage()">Start</button> function startImage(){ document.getElementById("pic").setAttribute(

TypeError: node.setAttribute is not a function

有些话、适合烂在心里 提交于 2019-12-07 11:17:26
问题 I'm getting an error: "TypeError: item.setAttribute is not a function" when I try to call the following function on my webpage: function list() { var colors = document.getElementById('colors'); var colors = colors.childNodes.length; for (var i = 1; i < broj; i++) { var item = colors.childNodes.item(i); item.setAttribute("id", i); item.setAttribute("onmouseover", "moveover(src)"); item.setAttribute("alt", "Color"); item.hspace = "2"; item.height = "23"; } } function moveover(colorAddress) {

How to set alignment for WKInterface Label using setAttributedText

别说谁变了你拦得住时间么 提交于 2019-12-06 00:58:12
I'm trying to set alignment for WKInterfaceLabel using setAttributedText function. Here is my code: var paragraphStyle = NSParagraphStyle.defaultParagraphStyle() paragraphStyle.alignment = NSTextAlignment.Center var attributedDictonary = [NSForegroundColorAttributeName:UIColor.greenColor(), NSParagraphStyleAttributeName:paragraphStyle] var attributeString = NSAttributedString(string: "TextAttributed", attributes: attributedDictonary) self.titleLabel.setAttributedText(attributeString) But I got a problem with this line: paragraphStyle.alignment = NSTextAlignment.Center I got error: Cannot

TypeError: node.setAttribute is not a function

天涯浪子 提交于 2019-12-05 12:11:29
I'm getting an error: "TypeError: item.setAttribute is not a function" when I try to call the following function on my webpage: function list() { var colors = document.getElementById('colors'); var colors = colors.childNodes.length; for (var i = 1; i < broj; i++) { var item = colors.childNodes.item(i); item.setAttribute("id", i); item.setAttribute("onmouseover", "moveover(src)"); item.setAttribute("alt", "Color"); item.hspace = "2"; item.height = "23"; } } function moveover(colorAddress) { var source = colorAddress; var image = source.slice(0, source.length - 4); var start = "url("; var

Javascript set value of an input field

大城市里の小女人 提交于 2019-12-04 04:58:19
Since while I cannot set the value of an input field with type=text. Before, I always used something like this: <input style="display: none" type="text" name="geo_poi" value="" id="geofeld" /> Then, in JavaScript i added code containing a line like this: document.getElementById("geofeld").value = geo_poi; This always worked. Maybe the new browsers don't want to support the method above anymore. So using the following method for setting attributes worked fine. document.getElementById("geofeld").setAttribute("value", geo_poi); For situations when setAttribute does not yield any result (think

How to Set OnClick attribute with value containing function in ie8?

你离开我真会死。 提交于 2019-12-03 06:23:07
问题 My goal is to change the onclick attribute of a link. I can do it successfully, but the resulting link doesn't work in ie8. It does work in ff3. For example, this works in Firefox 3, but not IE8. Why? <p><a id="bar" href="#" onclick="temp()">click me</a></p> <script> doIt = function() { alert('hello world!'); } foo = document.getElementById("bar"); foo.setAttribute("onclick","javascript:doIt();"); </script> 回答1: You don't need to use setAttribute for that - This code works (IE8 also) <div id=

JavaScript Adding an ID attribute to another created Element

妖精的绣舞 提交于 2019-12-03 04:43:22
问题 I have some code here that will do the following. The code creates an element "p" then I append it to a "div" in the HTML. I would like that "p" I just created have an unique identifier (ID) and set the name of the ID. So later on when the user wants to delete the last created element it will be able to get the ID so it can removeChild. Here is the code: JavaScript: var $ = function (id) { return document.getElementById(id); } function ShowResponse () { var myResponse = $("myresponse").value;

JavaScript Adding an ID attribute to another created Element

你说的曾经没有我的故事 提交于 2019-12-02 19:01:39
I have some code here that will do the following. The code creates an element "p" then I append it to a "div" in the HTML. I would like that "p" I just created have an unique identifier (ID) and set the name of the ID. So later on when the user wants to delete the last created element it will be able to get the ID so it can removeChild. Here is the code: JavaScript: var $ = function (id) { return document.getElementById(id); } function ShowResponse () { var myResponse = $("myresponse").value; var myPara = document.createElement("p"); var myDiv = $("mydiv"); myDiv.appendChild(myPara); var myID

How to Set OnClick attribute with value containing function in ie8?

我的梦境 提交于 2019-12-02 18:52:08
My goal is to change the onclick attribute of a link. I can do it successfully, but the resulting link doesn't work in ie8. It does work in ff3. For example, this works in Firefox 3, but not IE8. Why? <p><a id="bar" href="#" onclick="temp()">click me</a></p> <script> doIt = function() { alert('hello world!'); } foo = document.getElementById("bar"); foo.setAttribute("onclick","javascript:doIt();"); </script> You don't need to use setAttribute for that - This code works (IE8 also) <div id="something" >Hello</div> <script type="text/javascript" > (function() { document.getElementById("something")