admin管理员组

文章数量:1279113

What I want to do is to get the value of value and open it in new window with a specific size using JavaScript.

HTML

<a id="LNK" href="##" value="edit2.aspx?ren=<%# Eval("GLR_ID") %>" onclick="clickLink()">RENAME</a>

JavaScript

<script type="text/javascript">
        function clickLink() {
           var myLink = //I need to get the value of `value`
           window.open(myLink,'Rename','height=150px','width=250px');
           return false;
        }
</script> 

Please correct my grammar, Thank You.

What I want to do is to get the value of value and open it in new window with a specific size using JavaScript.

HTML

<a id="LNK" href="##" value="edit2.aspx?ren=<%# Eval("GLR_ID") %>" onclick="clickLink()">RENAME</a>

JavaScript

<script type="text/javascript">
        function clickLink() {
           var myLink = //I need to get the value of `value`
           window.open(myLink,'Rename','height=150px','width=250px');
           return false;
        }
</script> 

Please correct my grammar, Thank You.

Share Improve this question asked Aug 30, 2013 at 3:23 Onel SarmientoOnel Sarmiento 1,6264 gold badges20 silver badges46 bronze badges 1
  • The <%# tags seem to indicate to me that this involves more than just HTML and Javascript. Off the top of my head, though, I don't actually know what serverside language that is... – Katana314 Commented Aug 30, 2013 at 3:25
Add a ment  | 

5 Answers 5

Reset to default 2

http://jsfiddle/trevordixon/4HE97/

Pass a reference to the anchor to clickLink:

<a id="LNK" href="##" value="edit2.aspx?ren=<%# Eval("GLR_ID") %>" onclick="clickLink(this)">RENAME</a>

Use getAttribute to get the value:

    function clickLink(a) {
       var myLink = a.getAttribute('value');
       window.open(myLink,'Rename','height=150px','width=250px');
       return false;
    }
document.getElementById("LNK").getAttribute("value");

You can get DOM value using getElementByID().value

document.getElementByID('LNK').value

OR

You can pass argument into your onClick function.

onclick="clickLink(this.value)"

and in function.

function clickLink(value) {
var myLink = value;

Check out this solution:

function clickLink(e) {
  var myLink = e.getAttribute("value");
  window.open(myLink,'Rename','height=150px','width=250px');
  return false;
}

HTML:<a id="LNK" href="##" value="edit2" onclick="clickLink(this)">RENAME</a>

A working example can be found here

Try this

 window.clickLink = function(a) {
           var myLink = a.getAttribute('value');
           window.open(myLink,'Rename','height=150px','width=250px');
           return false;
        }

本文标签: htmlGet a href value using JavaScript and open it new windowStack Overflow