开发者

Adding a javascript variable to html

开发者 https://www.devze.com 2023-03-06 03:00 出处:网络
I need to add some JavaScript into my HTML. I have a JavaScript variable. How can I add it to my HTML code?

I need to add some JavaScript into my HTML.

I have a JavaScript variable. How can I add it to my HTML code?

<a href="index.php?s开发者_如何转开发omething=MYJAVASCRIPT VARIABLE">

UPDATE: Tried this:

<a href="#"  onclick="window.location.href = 'index.php?month=' +thisyear+'-1-1'" rel="external"> Jan </a>

But it's not working for some reason...


Adding the js contents of the variable into a $_GET parameter for PHP to use.

<script type="text/javascript">
    var myvar = 'THIS_IS_MY_JS_CONTENT';
</script>

<a href="#" onclick="window.location.href = 'something.php?variable=' + myvar">Variable</a>

View it live here: http://jsfiddle.net/kuroir/kmquk/


You can propably use something like :

  <a href="#"
     onclick="window.location.href='index.php?something='+yourJavascriptVariable"/>


you may write it like this:

<div id="content"></div>

and your js is <head>

$(function(){
  var name = "Pr0fess0rX";
  $("#content").html("<div><h3>" + name + "</h3></div>");
});


You can give ID to h3 tag or find it by jQuery and give value of variable to innerText property of found control.

For example <div><h3 id="mytagID"></h3></div>

function DoSomething() {
   var myTag = document.getElementById("mytagID");
   myTag.innerText = myvariableValue;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号