我有三个文件.XML,绘图函数和主Activity.LinearLayout我的XML文件中有一些.
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ef3"
android:id="@+id/img01"/>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#E8A2B4"
android:id="@+id/img02"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这是绘图功能:
public class getBorder extends TextView {
public getBorder(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
paint.setColor(android.graphics.Color.RED);
canvas.drawLine(0, 0, this.getWidth() - 1, 0, paint);
canvas.drawLine(0, 0, 0, this.getHeight() - 1, paint);
canvas.drawLine(this.getWidth() - 1, 0, this.getWidth() - 1,
this.getHeight() - 1, paint);
canvas.drawLine(0, this.getHeight() - 1, this.getWidth() - 1,
this.getHeight() …Run Code Online (Sandbox Code Playgroud) 这是我的代码:
<table>
<tr>
<td>Sales Promotion</td>
<td><input type="radio" name="q12_3" value="1">1</td>
<td><input type="radio" name="q12_3" value="2">2</td>
<td><input type="radio" name="q12_3" value="3">3</td>
<td><input type="radio" name="q12_3" value="4">4</td>
<td><input type="radio" name="q12_3" value="5">5</td>
</tr>
</table>
<button id="submit">submit</button>
Run Code Online (Sandbox Code Playgroud)
这是JS:
$(function(){
$("#submit").click(function(){
alert($('input[name=q12_3]').val());
});
});
Run Code Online (Sandbox Code Playgroud)
这是JSFIDDLE!每次我点击按钮它都会返回1.为什么?谁能帮我?
我写了一个css3动画,它只执行一次.动画运行良好,但在动画结束时会重置.我怎么能避免这种情况,我想保留结果而不是重置它.
$(function() {
$("#fdiv").delay(1000).addClass("go");
});Run Code Online (Sandbox Code Playgroud)
#fdiv {
width: 10px;
height: 10px;
position: absolute;
margin-left: -5px;
margin-top: -5px;
left: 50%;
top: 50%;
background-color: red;
}
.go {
-webkit-animation: spinAndZoom 1s 1;
}
@-webkit-keyframes spinAndZoom {
0% {
width: 10px;
height: 10px;
margin-left: -5px;
margin-top: -5px;
-webkit-transform: rotateZ(0deg);
}
100% {
width: 400px;
height: 400px;
margin-left: -200px;
margin-top: -200px;
-webkit-transform: rotateZ(360deg);
}
}Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id="fdiv"></div>Run Code Online (Sandbox Code Playgroud)
这是演示.
我有一个程序,它运作良好.见这里.
这是代码:
<div id="round"></div>
<style>
#round{
position: absolute;
width: 200px;
height: 200px;
border-radius: 50%;
left: 400px;
top: 200px;
background-color: #e1e1e1;
}
</style>
<script src="jquery.js"></script>
<script src="jquery.easing.1.3.js"></script>
<script>
$(document).ready(function(){
$("#round").click(function(){
setInterval(function(){
$("#round").animate(
{height: 250,
width: 150,
top:150,
left: 425},
{duration: 300}
).
animate(
{height: 200,
width: 200,
top:200,
left: 400},
{duration: 300}
);
}, 0);
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
但是当我将"#round"改为"this"时.它不会起作用.为什么?(实际上它可以工作,但是当我把它们放入setInterval()时,它将无法工作)
$(document).ready(function(){
$("#round").click(function(){
setInterval(function(){
$("#round").animate(
{height: 250,
width: 150,
top:150,
left: 425},
{duration: 300}
).
animate(
{height: 200,
width: 200,
top:200, …Run Code Online (Sandbox Code Playgroud) 有人能告诉我如何一次从阵列中选择几个不同的随机数?例如,有一个long int数组.我想从中挑选7个数字.所有数字必须不相同,并按增加顺序对它们进行排序.
Random random = new Random();
int a = mixColor[random.nextInt(mixColor.length)];
int b = mixCoor[random.nextInt(mixCoor.length)];
int c = mixCoor[random.nextInt(mixCoor.length)];
int d = mixCoor[random.nextInt(mixCoor.length)];
int e = mixCoor[random.nextInt(mixCoor.length)];
while(b!=c && c!=d && b!=d) {
b = mixCoor[random.nextInt(mixCoor.length)];
c = mixCoor[random.nextInt(mixCoor.length)];
d = mixCoor[random.nextInt(mixCoor.length)];
}
Run Code Online (Sandbox Code Playgroud)
mixColor[]并且mixCoor[]是长int数组.我可以用这种方式做,但如果我想选更多数字,这将非常复杂.我也需要对它们进行排序.有人得到好主意吗?
假设有两个对象。
const a = [
{ id: '1-1-1', name: 'a111' },
{ id: '1-1-2', name: 'a112' },
{ id: '1-2-1', name: 'a121' },
{ id: '1-2-2', name: 'a122' },
{ id: '2-1-1', name: 'a211' },
{ id: '2-1-2', name: 'a212' }
]
const b = ['1-1', '1-2', '2-1']
Run Code Online (Sandbox Code Playgroud)
和结果
{
'1-1':[
{ id: '1-1-1', name: 'a111' },
{ id: '1-1-2', name: 'a112' },
],
'1-2':[
{ id: '1-2-1', name: 'a121' },
{ id: '1-2-2', name: 'a122' },
],
'2-1':[
{ …Run Code Online (Sandbox Code Playgroud) 我有一个HTML表单,并在点击提交按钮时将数据发送到php文件.
$.ajax({
url: "text.php",
type: "POST",
data: {
amount: amount,
firstName: firstName,
lastName: lastName,
email: email
},
dataType: "JSON",
success: function (data) {
console.log("ok");
$("#result").text(data);
}
});
Run Code Online (Sandbox Code Playgroud)
在PHP中:
<?php
$amount = $_POST["amount"];
$firstName = $_POST["firstName"];
$lastName = $_POST["lastName"];
$email = $_POST["email"];
if(isset($amount)){
$data = array(
"amount" => $amount,
"firstName" => $firstName,
"lastName" => $lastName,
"email" => $email
);
echo json_encode($data);
}
?>
Run Code Online (Sandbox Code Playgroud)
结果是[对象对象].我想要一个类似的类型:
{"Amount":"12.34", "FirstName":"Any", "LastName":"Tester", "Email":"a.test@something.com"}
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
我有一个XML文件,比如
<stock><name>AXL</name><time>19-07</time><price>11.34</price></stock>
<stock><name>AIK</name><time>19-07</time><price>13.54</price></stock>
<stock><name>ALO</name><time>19-07</time><price>16.32</price></stock>
<stock><name>APO</name><time>19-07</time><price>13.56</price></stock>
...............more
Run Code Online (Sandbox Code Playgroud)
如何将其解析为JSON结构文件?
我真的很困惑与此三种功能:removeAllViewsInLayout(),postInvalidate()和refreshDrawableState().
removeAllViewsInLayout()
Run Code Online (Sandbox Code Playgroud)
当我removeAllViewsInLayout()在我的程序中使用时,所有视图都消失了.但是当触发postInvalidate()刷新时,什么也没有.我想removeAllViewsInLayout()删除我的所有观点.有没有办法清除我视图中的所有内容但不删除它?
postInvalidate()
Run Code Online (Sandbox Code Playgroud)
我想刷新我的观点.但是refreshDrawableState(),我只能做一次,为什么?
这是jsfiddle.HTML:
<div class="main">
<div class="div1"></div>
Center with Red!
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
.main{
height: 50px;
width: 100%;
background-color: #000000;
text-align: center;
color: #ffffff;
line-height: 50px;
font-size: 24px;
}
.div1{
display: inline-block;
width: 50px;
height: 50px;
background-color: #ff0000;
}
Run Code Online (Sandbox Code Playgroud)
红色div和文本居中.但为什么行高不起作用.文本不是垂直居中的.我认为原因可能是线条高度在线性布局中不起作用,但父div是块布局.如何垂直和水平居中红色div和文本.文本可能会被更改,所以我不想设置它们的绝对位置并使用如下代码:
margin-left: -25px;
margin-top: -25px;
left: 50%;
top: 50%;
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助!
javascript ×4
jquery ×3
android ×2
css ×2
java ×2
json ×2
ajax ×1
arrays ×1
css3 ×1
draw ×1
ecmascript-6 ×1
ecmascript-7 ×1
php ×1
xml ×1
xml-parsing ×1