我在resources/static
:
index.html
,app.js
,login/login.html
,login/login.js
。在index.html
我希望有一个按钮,当您点击它时,您会转到login/login.html
。我想用纯Javascript来做。最简单的方法是什么?
答案 0 :(得分:1)
'标准'这样做没有js
<a href="login/login.html">click me to get redirected to login</a>
&#39; js way&#39;这样做:
HTML:
<button onclick="redirectToLogin();">Press me to get into login page</button>
的javascript:
function redirectToLogin(){
window.location.href = "login/login.html";
}
或jQuery方式:
HTML:
<button id="loginbutton">Press me to get into login page</button>
的javascript:
$('#loginbutton').on('click', function(){
window.location.href = "login/login.html";
}
答案 1 :(得分:0)
只需在html中创建一个这样的按钮即可。
<button id="myButton" class="float-left submit-button" >GO to Login Page</button>
使用javascript在按钮中使用onclick
操作。
<script type="text/javascript">
document.getElementById("myButton").onclick = function () {
location.href = "login/login.html";
};
</script>
答案 2 :(得分:0)
HTML:
val gp=df.groupBy("accountid","date").agg(collect_list("key").as("key"))
val joined = df2.join(gp, Seq("date", "accountid") , "left_outer")
joined.show(false)
//+--------------+---------+----------------------------------------+------------+
//|date |accountid|result |key |
//+--------------+---------+----------------------------------------+------------+
//|20180610114049|id2 |{'key1':'0.0','key2':'0.0','key3':'0.0'}|[key2] |
//|20180613114049|id3 |{'key1':'0.0','key2':'0.0','key3':'0.0'}|[key2, key3]|
//|20180610114049|id1 |{'key1':'0.0','key2':'0.0','key3':'0.0'}|[key1, key1]|
//|20180611114049|id1 |{'key1':'0.0','key2':'0.0','key3':'0.0'}|null |
//|20180612114049|id2 |{'key1':'0.0','key2':'0.0','key3':'0.0'}|[key1] |
//+--------------+---------+----------------------------------------+------------+
// the UDF that will do the most work
// it's important to declare `formats` inside the function
// to avoid object not Serializable exception
// Not all cases are covered, use with caution :D
val convertJsonValues = udf{(json: String, arr: Seq[String]) =>
import org.json4s.jackson.JsonMethods._
import org.json4s.JsonDSL._
implicit val format = org.json4s.DefaultFormats
// replace single quotes with double
val kvMap = parse(json.replaceAll("'", """"""")).values.asInstanceOf[Map[String,String]]
val updatedKV = kvMap.map{ case(k,v) => if(arr.contains(k)) (k,"1.0") else (k,v) }
compact(render(updatedKV))
}
// Use when-otherwise and send empty array where `key` is null
joined.select($"date",
$"accountid",
when($"key".isNull, convertJsonValues($"result", array()))
.otherwise(convertJsonValues($"result", $"key"))
.as("result")
).show(false)
//+--------------+---------+----------------------------------------+
//|date |accountid|result |
//+--------------+---------+----------------------------------------+
//|20180610114049|id2 |{"key1":"0.0","key2":"1.0","key3":"0.0"}|
//|20180613114049|id3 |{"key1":"0.0","key2":"1.0","key3":"1.0"}|
//|20180610114049|id1 |{"key1":"1.0","key2":"0.0","key3":"0.0"}|
//|20180611114049|id1 |{"key1":"0.0","key2":"0.0","key3":"0.0"}|
//|20180612114049|id2 |{"key1":"1.0","key2":"0.0","key3":"0.0"}|
//+--------------+---------+----------------------------------------+
的javascript:
<button onclick="goToLogin();" >click here to go on login </button>
注意:请检查此测试并确定更好的测试: https://jsperf.com/location-href-vs-location-assign/14