只是一个简单的问题.我在使用onclick javascript的div中遇到问题.当我点击内部div时,它应该只触发它的onclick javascript,但外部div的javascript也被触发了.如何在不激发外部div的javascript的情况下点击内部div?
<html>
<body>
<div onclick="alert('outer');" style="width:300px;height:300px;background-color:green;padding:5px;">outer div
<div onclick="alert('inner');" style="width:200px;height:200px;background-color:white;" />inner div</div>
</div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我目前正在制作基本表格.我想用这个表单做的是当你点击提交/按钮来首先改变一个字段的值然后像往常一样提交表单.这看起来有点像这样:
<form name="myform" id="myform" action="action.php">
<input type="hidden" name="myinput" value="0" />
<input type="text" name="message" value="" />
<input type="submit" name="submit" onclick="DoSubmit()" />
</form>
Run Code Online (Sandbox Code Playgroud)
这就是我带来JavaScript的程度.它将"myinput"的值更改为1,但不提交表单.我真的是一个JavaScript noobie,请原谅我,如果这只是一个太简单的问题,但我真的没有得到它的支持.
function DoSubmit(){
document.myform.myinput.value = '1';
document.getElementById("myform").submit();
}
Run Code Online (Sandbox Code Playgroud) 我动态创建一个新的div(带有"textbox"类和ID),以及其中的一些其他元素,稍后在我的代码中我将其绑定div到click事件,并显示单击的元素,如下所示:
$('#textbox_'+i).bind('click', function(event){
alert(event.target.className);
}
Run Code Online (Sandbox Code Playgroud)
这很好,它会给我textbox一个显示的类.但event.target.hasClass()似乎没有用.所以,当我执行以下操作时,没有任何反应:
$('#textbox_'+i).bind('click', function(event){
if(event.target.hasClass('textbox')) { alert('got it!'); }
}
Run Code Online (Sandbox Code Playgroud)
我尝试了几种不同的方式,在我看来,event.target.hasClass()这是行不通的.有没有其他方式来处理事件或我做错了什么?
我想实现一个TabLayout因为它很简单,但我发现的所有教程都涉及到ViewPager.我只是想要一个类似的OnClickListener地方,如果我点击Add图标,它将显示一个显示"选项卡1"的吐司,如果我点击一个日历图标,它将显示一个显示"标签2"的吐司
我想使用,TabLayout因为它处理设备旋转.
Main_activity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
// Add five tabs. Three have icons and two have text titles
tabLayout.addTab(tabLayout.newTab().setIcon(R.drawable.add_live));
tabLayout.addTab(tabLayout.newTab().setIcon(R.drawable.calendar_live));
tabLayout.addTab(tabLayout.newTab().setIcon(R.drawable.group_live));
tabLayout.addTab(tabLayout.newTab().setText("Send"));
tabLayout.addTab(tabLayout.newTab().setText("Send & Post"));
}
}
Run Code Online (Sandbox Code Playgroud)
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:app="http://schemas.android.com/tools">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 如何使用 Jetpack Compose 通过单击按钮以编程方式打开外部 URL?
@Composable
fun MyButton() {
Button(onClick = {
//enter code here
})
}
Run Code Online (Sandbox Code Playgroud) 我正在jsfiddle上测试一些javascript,由于某种原因,我无法在按钮点击时触发一个函数.有什么建议?
我在尝试弄清楚如何使我的代码的某些部分工作时遇到了一些麻烦.
<input type="checkbox" id="check_all_1" name="check_all_1" title="Select All" onclick="selectAll(document.wizard_form, this);">
<label for="check_all_1" onclick="toggleCheckbox('check_all_1'); return false;">Select All</label>
Run Code Online (Sandbox Code Playgroud)
这是我的HTML工作原理(单击文本将单击该框).它的javascript非常简单:
function toggleCheckbox(id) {
document.getElementById(id).checked = !document.getElementById(id).checked;
}
Run Code Online (Sandbox Code Playgroud)
但是,当标签是单击复选框的时候,我希望输入发生onclick.在这个当前时间onClick js不会去.关于如何做到这一点的一个建议是什么?我试图将输入的onclick添加到标签的onclick,但这不起作用.
任何建议/解决方案都会很精彩.
在用户点击...."登录"按钮和其他事件后,我制作了一个加载脚本 - 让用户知道他们必须等待(直到ajax回复).
我如何可以禁用任何鼠标点击(右键单击,左键单击,双击,中键单击,X点击),上div id="doc"?
我想将该代码添加到loading.js
HTML
<html>
...
<body>
<div id="doc">
<div id="content">
...
<input type="button" value="Login" id="login" />
...
</div id="content">
</div id="doc">
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
loading.js
function load_bar(x)
{
if (x==0)
{
$(document.body).css( {"cursor": "default"} );
$("body").css( {"cursor": "default"} );
$("#loading").css("visibility", "hidden"); //modal window
// $("#doc").....ENABLE all clicks (left/right/etc)
}
else if (x==1)
{
$(document.body).css( {"cursor": "wait"} );
$("body").css( {"cursor": "wait"} );
$("#loading").css( {"visibility": "visible"} ); //modal window
// $("#doc").....DISABLE all clicks (left/right/etc)
} …Run Code Online (Sandbox Code Playgroud) 假设我在带有角度ng-click事件的列表中有这个项目.
<a data-id='102' ng-click='delete()'>Delete</a>
Run Code Online (Sandbox Code Playgroud)
如果this那么我如何获得数据/信息?
$scope.delete = function() {
var id = $(this).attr('data-id');
console.log(id); // I want to get 102 as the result
if (confirm('Are you sure to delete?')) {
$('#contactsGrid tr[data-id="' + id + '"]').hide('slow');
}
};
Run Code Online (Sandbox Code Playgroud)