我想创建一个没有任何关系的链接,这意味着它是一个假链接
我尝试使用onclick =" mijava();返回false;"但它在网站上滚动
我该怎么做?
答案 0 :(得分:3)
的javascript:
document.getElementById("nothing").addEventListener("click", function(event){
event.preventDefault()
});
HTML:
<a id="nothing" href="#">Link</a>
答案 1 :(得分:2)
"javascript:void(0)"
到href
属性,<a>
标记将不执行任何操作。
答案 2 :(得分:1)
这不会做任何事情。
<a href="">Link</a>
答案 3 :(得分:0)
您可以使用CSS将其设置为类似链接的样式,如果它不会像一个锚定标记那样,您可能不想使用锚标记。
答案 4 :(得分:0)
你测试它吗?
public class ElemType
{
public string MyProperty { get; set; }
}
public static class ElemTypePropertySelector
{
private static Dictionary<string, Func<string[], Func<ElemType, bool>>> dictionary = new Dictionary<string, Func<string[], Func<ElemType, bool>>>();
public static IEnumerable<ElemType> WhereIn(this IEnumerable<ElemType> query, string filterFieldName, string[] values) {
var cachedFactory = GetOrAdd(filterFieldName);
var contains = cachedFactory(values);
return query.Where(contains);
}
private static Func<string[], Func<ElemType, bool>> GetOrAdd(string filterFieldName) {
Func<string[], Func<ElemType, bool>> cachedFunc;
if (!dictionary.TryGetValue(filterFieldName, out cachedFunc)) {
cachedFunc = CreateFactory(filterFieldName);
dictionary.Add(filterFieldName, cachedFunc);
}
return cachedFunc;
}
private static Func<string[], Func<ElemType, bool>> CreateFactory(string filterFieldName) {
MethodInfo mi = typeof(Enumerable).GetMethods().Where(x => string.Equals(x.Name, "Contains", StringComparison.OrdinalIgnoreCase)).Single(x => x.GetParameters().Length == 2).MakeGenericMethod(typeof(string));
PropertyInfo pi = typeof(ElemType).GetProperty(filterFieldName);
ParameterExpression arrExpression = Expression.Parameter(typeof(string[]), "arr");
ParameterExpression rtParam = Expression.Parameter(typeof(ElemType), "et");
var callExpression = Expression.Call(null, mi, new Expression[] { arrExpression, Expression.Property(rtParam, pi) });
var innerExpression = Expression.Lambda<Func<ElemType, bool>>(callExpression, new[] { rtParam });
var expression = Expression.Lambda<Func<string[], Func<ElemType, bool>>>(innerExpression, new ParameterExpression[] { arrExpression });
return expression.Compile();
}
}
class Program
{
static void Main(string[] args) {
var query = new List<ElemType> {
new ElemType { MyProperty = "aaa" },
new ElemType { MyProperty = "bbb" },
new ElemType { MyProperty = "cccc" }
};
var result = query.WhereIn("MyProperty", new[] { "aaa", "bbb" });
}
}