我有这个javascript代码:
<script ="text/javascript">
var newUrl=window.location.href;
var pathArray="";
pathArray=newUrl.substr(newUrl.lastIndexOf("?")+1);
</script>
Run Code Online (Sandbox Code Playgroud)
我想使用pathArray变量作为标签上href的一部分
这是我的HTML代码
<a href="game.html?"+pathArray>
<img src="img/RestartButton.png" style="position:absolute;
left:80px; top:220px">
</a>
Run Code Online (Sandbox Code Playgroud)
但似乎它不读取变量的值,而是它的名称.
我有像这样的HTML代码
<html>
<script type="text/javascript" src='LatihanKuisJs.js'></script>
<body>
<form name="kuis">
<table border="1" width="50%">
<tr>
<th colspan="2" >Celcius
</tr>
<tr>
<td align="center" width="80%">Kelvin</td>
<td align="center"><input type="text" id="kelvin">
</td>
</tr>
<tr>
<td align="center" width="80%">Reamur</td>
<td align="center"><input type="text" id="reamur"></td>
</tr>
<tr>
<td align="center" width="80%">Fahrenheit</td>
<td align="center"><input type="text" id="fahrenheit"></td>
</tr>
</table>
<input type="button" value="Calculate" onclick='calculateCelcius();'/>
<br/><br/>
<textarea rows="20" cols="90" id="textarea">
</textarea>
<br/><br/>
<input type="button" value="Clear" onclick='clear();'/>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
和外部JavaScript函数如下:
function calculateCelcius(){
var kelvin = document.getElementById('kelvin');
var reamur = document.getElementById('reamur');
var fahrenheit = document.getElementById('fahrenheit');
var textarea …Run Code Online (Sandbox Code Playgroud) 所以我在动作栏上有菜单项.在onOptionsItemSelected上,我想更改菜单项图像.
这是我的代码
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.todaySched:{
viewTodaySched();
item.setIcon(R.drawable.calendarselected);
infoLog=(MenuItem)findViewById(R.id.infoLog);
infoLog.setIcon(R.drawable.book);
return true;}
case R.id.infoLog:{
viewInfoLog();
item.setIcon(R.drawable.bookselected);
todaySched=(MenuItem)findViewById(R.id.todaySched);
todaySched.setIcon(R.drawable.calenderselected);
return true;}
default:
return super.onOptionsItemSelected(item);
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我点击它时图标不会改变,我得到了运行时错误.例如:当我点击todaySched图标时,好像我无法获取infoLog项目ID.
我的LogCat:LogCat