获取内容的上下文onClick(View view),按钮的回调onClickListener()很容易:
view.getContext()
Run Code Online (Sandbox Code Playgroud)
但我无法弄清楚如何获得上下文中onClick(DialogInterface v, int buttonId),对于回调对话框的onClickListener
public class MainActivity extends Activity implements android.content.DialogInterface.OnClickListener
Run Code Online (Sandbox Code Playgroud)
这可能吗?
这似乎是最简单的事情,但它只是不起作用.在普通的浏览器中,.html和.js文件工作正常,但在Chrome扩展程序中,该onClick功能没有执行它应该执行的操作.
.js文件:
function hellYeah(text) {
document.getElementById("text-holder").innerHTML = text;
}
Run Code Online (Sandbox Code Playgroud)
.html文件:
<!doctype html>
<html>
<head>
<title>
Getting Started Extension's Popup
</title>
<script src="popup.js"></script>
</head>
<body>
<div id="text-holder">
ha
</div>
<br />
<a onClick=hellYeah("xxx")>
hyhy
</a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
所以基本上一旦用户点击"hyhy","ha"应该变成"xxx".再次 - 它在浏览器中完美运行,但在扩展中不起作用.你知道为什么吗?以防我在下面附上manifest.json.
提前致谢!
manifest.json的:
{
"name": "My First Extension",
"version": "1.0",
"manifest_version": 2,
"description": "The first extension that I made.",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [
"http://api.flickr.com/"
]
}
Run Code Online (Sandbox Code Playgroud) 我有一个带有较小TextView子项的自定义LinearLayout.我希望能够单击TextView未覆盖的区域,因此我将clickable = true和onclicklistener设置为LinearLayout,但不会触发onClick.如果我在TextView上设置onclick监听器,它按预期工作...
有人可以帮忙吗?
ar_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ar_item" android:layout_width="202dp"
android:layout_height="62dp" android:background="@drawable/bg_item_ar"
android:clickable="true">
<TextView android:id="@+id/ar_item_txt"
android:layout_width="164dp" android:layout_height="fill_parent"
android:paddingBottom="8dp" android:paddingLeft="8dp"
android:paddingTop="8dp" android:paddingRight="6dp" android:gravity="center"
android:background="#50000000" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我的自定义LinearLayout
public class ARView extends LinearLayout
{
public ARView(final Context context, String name, String id)
{
super(context);
getLayoutInflater().inflate(R.layout.ar_item, this ,true);
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.ar_item, null);
TextView textView = (TextView) findViewById(R.id.ar_item_txt);
textView.setText(name);
setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Toast t = Toast.makeText(context, "hey!", Toast.LENGTH_SHORT);
t.show();
}
});
}
}
Run Code Online (Sandbox Code Playgroud) 当我单击此按钮时,我希望值更改.HTML:
<input onclick="change()" type="button" value="Open Curtain" id="myButton1"></input>
Run Code Online (Sandbox Code Playgroud)
使用Javascript:
function change();
{
document.getElementById("myButton1").value="Close Curtain";
}
Run Code Online (Sandbox Code Playgroud)
按钮正在显示打开的窗帘,我希望它改为关闭窗帘,这是正确的吗?
我有一个如下按钮,
<asp:Button ID="pagerLeftButton" runat="server" OnClientClick="disable(this)" onclick="pager_Left_Click" Text="<" />
Run Code Online (Sandbox Code Playgroud)
当我使用我的按钮时,onclick不会触发.当我删除OnClientClick时,然后触发onclick.
我需要做的是,在回发期间禁用按钮并在回发结束后启用它.
编辑:附加信息:
我添加了断点,我的触发功能是c#部分,我正在调试,他们肯定没有开火.那些功能就像
protected void pager_Left_Click(object sender, EventArgs e)
{
//Do smthing.
}
protected void pager_Right_Click(object sender, EventArgs e)
{
//Do smthing.
}
Run Code Online (Sandbox Code Playgroud)
当我点击我的按钮时,它被禁用1-2秒并自动启用,但我不确定为什么它被启用.我没有添加任何部分,以便再次启用它.
我想使用JavaScript模拟页面上任何链接的点击.如果该链接具有与其"onclick"事件绑定的某些功能(由任何其他JS我没有任何控制),则必须调用该函数,否则链接应以正常方式运行并打开新页面.
我不确定只检查'onclick'处理程序的值就足够了.我想构建它,以便它适用于任何链接元素.
我无法使用任何JS库(不一定是jQuery)或简单地使用JavaScript来控制可能绑定到链接的onclick事件的函数.
编辑:在下面的答案的帮助下,看起来可以检查使用jQuery附加的事件处理程序或使用该onclick属性.如何检查使用addEventListener/任何其他JS库附加的事件处理程序,以便它是万无一失的?
我用一个活动和一个布局做了一个非常简单的测试应用程序.在onClick不触发其压在第一时间,因为它应该.
活动:
package com.example.mytest;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText ed1 = (EditText) findViewById(R.id.editText1);
ed1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "1", Toast.LENGTH_LONG)
.show();
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:ems="10" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText2" …Run Code Online (Sandbox Code Playgroud) 我在页面上有一个iframe,来自第三方(广告).我想在点击iframe时发出点击事件(记录一些内部统计数据).就像是:
$('#iframe_id').click(function() {
//run function that records clicks
});
Run Code Online (Sandbox Code Playgroud)
..基于HTML:
<iframe id="iframe_id" src="http://something.com"></iframe>
Run Code Online (Sandbox Code Playgroud)
我似乎无法得到任何变化的工作.思考?
我有这个功能:
function make(place)
{
place.innerHTML = "somthing"
}
Run Code Online (Sandbox Code Playgroud)
我曾经用纯JavaScript和HTML做到这一点:
<button onclick="make(this.parent)">click me</button>
Run Code Online (Sandbox Code Playgroud)
我怎么能用idiomatic knockout.js做到这一点?
我只是在学习javascript和php.我创建了一个联系表单,当我按下它时,我想要提交按钮来完成两件事:
<input id="submit" name="submit" type="submit" value="Submit" onclick="eatFood()">
<?php
if ($_POST['submit']) {
////?????
}
?>
Run Code Online (Sandbox Code Playgroud)
我将数据发送到我的电子邮箱,所以我明白了.但onclick功能似乎不起作用.我尝试查看添加onclick功能的提交按钮,但它没有帮助.